#include <bits/stdc++.h>

using namespace std;

const int MAXN = 4e4+10;

typedef long long ll;

int ls[MAXN],rs[MAXN],n;
ll f[MAXN][45][45],a[MAXN],b[MAXN],c[MAXN];

void dfs(int x,int l,int r){
	if(x >= n){
		for(int i = 0;i <= l;i++)
			for(int j = 0;j <= r;j++)
				f[x][i][j] = c[x] * (a[x] + i) * (b[x] + j);
		return;
	}
	dfs(ls[x],l+1,r);
	dfs(rs[x],l,r+1);
	for(int i = 0;i <= l;i++)
		for(int j = 0;j <= r;j++)
			f[x][i][j] = min(f[ls[x]][i+1][j] + f[rs[x]][i][j],f[ls[x]][i][j] + f[rs[x]][i][j+1]);
}

int main (){
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int x,y;scanf("%d %d",&x,&y);
		if(x < 0) x = n-x-1;
		if(y < 0) y = n-y-1;
		ls[i] = x; rs[i] = y;
	}
	for(int i = n;i < n<<1;i++) scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
	dfs(1,0,0);
	printf("%lld\n",f[1][0][0]);
	return 0;
}
